package com.lizhi.yun.sync.rsz.handler;/**
 * @program: hbsf_yun
 * @name RszTrjectoryInfoSyncHandler
 * @description: 固定处方训练信息
 * @author: lizhi
 * @create: 2021-11-17 08:39
 */

import com.lizhi.common.yun.entity.RpcServicePOJO;
import com.lizhi.common.yun.enums.HeartBeartEnum;
import com.lizhi.utils.StringUtils;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.rsz.dao.RszTrajectoryInfoDao;
import com.lizhi.yun.db.rsz.entity.RszTrajectoryInfoEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *@program: hbsf_yun
 *@name RszTrjectoryInfoSyncHandler
 *@description: 固定处方训练信息
 *@author: lizhi
 *@create: 2021-11-17 08:39
 */
@Slf4j
@Service
public class RszTrajectoryInfoSyncHandler {

    @Resource
    private RszTrajectoryInfoDao rszTrajectoryInfoDao;

    public String recv(String json){
        RpcServicePOJO rpcServicePOJO = new RpcServicePOJO();
        try {
            RszTrajectoryInfoEntity rszTrajectoryInfoEntity = SamJsonUtil.toObject(json, RszTrajectoryInfoEntity.class);
            log.info("康复磨砂卓固定处方信息上传:{}", rszTrajectoryInfoEntity);
            RszTrajectoryInfoEntity trajectoryInfoEntity = rszTrajectoryInfoDao.selectById(rszTrajectoryInfoEntity.traId, rszTrajectoryInfoEntity.hospitalId, rszTrajectoryInfoEntity.hospitalSystemId);
            if (!StringUtils.isEmpty(trajectoryInfoEntity)){
                rszTrajectoryInfoEntity.lid = trajectoryInfoEntity.lid;
                rszTrajectoryInfoDao.updateByIdSelective(rszTrajectoryInfoEntity);
            } else {
                rszTrajectoryInfoEntity.lid = StringUtils.newId();
                rszTrajectoryInfoDao.insertRecord(rszTrajectoryInfoEntity);
            }
            rpcServicePOJO.setErrorCode(HeartBeartEnum.HEART_BEART_000000.getEnValue());
            rpcServicePOJO.setMessage(HeartBeartEnum.HEART_BEART_000000.getEnName());
        } catch (Exception e){
            e.printStackTrace();
        }
        return SamJsonUtil.toJson(rpcServicePOJO);
    }
}
